const myArray = [1, 2, [3, 4, 5, [6, [7]]], 8, [9]]

const flatArray = []
const flatten = (array) => {
	for (let i in array) {
		if (Array.isArray(array[i])) { //每一项是否为数组
			flatten(array[i]) //继续遍历
		} else {
			flatArray.push(array[i])
		}
	}
	return flatArray
}
const res = flatten(myArray)
console.log(res);
